package com.shadow.cloud.security;

import com.shadow.cloud.framework.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.event.EventListener;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Slf4j
@EntityScan("com.shadow.cloud")
@ComponentScan("com.shadow.cloud")
@SpringBootApplication
public class SecurityApp {

    @Autowired
    BCryptPasswordEncoder encoder;

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SecurityApp.class, args);
    }

    @EventListener(ApplicationReadyEvent.class)
    public void onApplicationReady() {
//        BCryptPasswordEncoder bean = BeanUtil.getBeanByName("passwordEncoder", BCryptPasswordEncoder.class);
//        BCryptPasswordEncoder bean = SpringContextUtils.getBean("passwordEncoder");
        String encode = encoder.encode("1");
//        String encode = BCryptPasswordUtils.encryptPassword("1");
        log.info("BCryptPasswordUtils encode : {}", encode);
    }
}
